﻿namespace Resonator.Core.Models
{
	using System;
	using System.IO;
	using System.Runtime.Remoting;

	public class NoCloseStream : Stream
	{
		private readonly Stream _inner;

		public NoCloseStream(Stream inner)
		{
			if( inner == null )
			{
				throw new ArgumentNullException( "inner" );
			}

			_inner = inner;
		}

		public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
		{
			return _inner.BeginRead( buffer, offset, count, callback, state );
		}

		public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
		{
			return _inner.BeginWrite( buffer, offset, count, callback, state );
		}

		public override bool CanTimeout
		{
			get { return _inner.CanTimeout; }
		}

		public override void Close()
		{
		}

		public override ObjRef CreateObjRef(Type requestedType)
		{
			return _inner.CreateObjRef( requestedType );
		}

		public override int EndRead(IAsyncResult asyncResult)
		{
			return _inner.EndRead( asyncResult );
		}

		public override void EndWrite(IAsyncResult asyncResult)
		{
			_inner.EndWrite( asyncResult );
		}

		public override object InitializeLifetimeService()
		{
			return _inner.InitializeLifetimeService();
		}

		public override int ReadByte()
		{
			return _inner.ReadByte();
		}

		public override int ReadTimeout
		{
			get { return _inner.ReadTimeout; }
			set { _inner.ReadTimeout = value; }
		}

		public override void WriteByte(byte value)
		{
			_inner.WriteByte( value );
		}

		public override int WriteTimeout
		{
			get { return _inner.WriteTimeout; }
			set { _inner.WriteTimeout = value; }
		}

		public override void Flush()
		{
			_inner.Flush();
		}

		public override long Seek(long offset, SeekOrigin origin)
		{
			return _inner.Seek( offset, origin );
		}

		public override void SetLength(long value)
		{
			_inner.SetLength( value );
		}

		public override int Read(byte[] buffer, int offset, int count)
		{
			return _inner.Read( buffer, offset, count );
		}

		public override void Write(byte[] buffer, int offset, int count)
		{
			_inner.Write( buffer, offset, count );
		}

		public override bool CanRead
		{
			get { return _inner.CanRead; }
		}

		public override bool CanSeek
		{
			get { return _inner.CanSeek; }
		}

		public override bool CanWrite
		{
			get { return _inner.CanWrite; }
		}

		public override long Length
		{
			get { return _inner.Length; }
		}

		public override long Position
		{
			get { return _inner.Position; }
			set { _inner.Position = value; }
		}
	}
}